using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MSRI.HelperClasses;
using Instedd.Labs.Geo.Library.Kml;
using Mvp.Xml.Common.Xsl;
using System.Xml;
using System.IO;
using System.Xml.Xsl;
using System.Collections.Specialized;

namespace Instedd.Labs.Geo.Library.Tests.Managers
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class FactoryUtilFixture
    {
        public FactoryUtilFixture()
        {
        }

        [TestMethod]
        public void NullInstanceCreatesANewInstance()
        {
            object instance = null;

            object createdInstance = FactoryUtil.CreateIfItIsNull(ref instance);

            Assert.IsNotNull(createdInstance);
        }

        [TestMethod]
        public void NotNullInstanceReturnsTheSameInstance()
        {
            object instance = new object();

            object createdInstance = FactoryUtil.CreateIfItIsNull(ref instance);

            Assert.AreSame(instance, createdInstance);
        }

        [TestMethod]
        public void NullInstanceAndFactoryMethodReturnsANewInstanceCreatedByTheFactoryMethod()
        {
            object instance = null;
            FactoryMethod<object> factoryMethod = delegate() { return "stringValue"; };

            object createdInstance = FactoryUtil.CreateIfItIsNull(ref instance, factoryMethod);

            Assert.IsNotNull(createdInstance);
            Assert.AreEqual("stringValue", (string)createdInstance);
        }
 
        [TestMethod]
        public void NotNullInstanceAndFactoryMethodReturnsTheSameInstance()
        {
            object instance = new object();
            FactoryMethod<object> factoryMethod = delegate() { return new object(); };

            object createdInstance = FactoryUtil.CreateIfItIsNull(ref instance, factoryMethod);

            Assert.AreSame(instance, createdInstance);
        }
    }
}